var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    facility_num:'',//设备号
  },


  
  //监听输入
  input_search:function(e){
    var that=this;
   that.setData({
     facility_num: e.detail.value
   })
  },
  //扫码
  scan: function () {
    var that=this;
    // 只允许从相机扫码
    wx.scanCode({
      onlyFromCamera: true,
      success: (res) => {
        //console.log("扫码获取到的结果", res.result);
        var newsp = res.result.split("=");
        //console.log(">>>>>>>>>>>>>>>>>>>",newsp)
        // console.log(newsp[2] != '')
        if (newsp.length == 2 && newsp[1] != '') {
            that.setData({
              facility_num: newsp[1]
            })
        } else {
          app.showToast('扫码失败请重试或者手动输入', "none", 2000, function () { });
        }

      }
    })
  },
  //查找 
  findBtn:function(){
    var that=this;
    if (that.data.facility_num==''){
      app.showToast('请输入或者扫描二维码');
      return false;
    }
    app.ajax({
          url: "Manage/Equipment/get_equipment",
          data: {
              eq_sn: that.data.facility_num,
          },
          success: function (res) {
              if (res.data.code == 200) {
                  wx.navigateTo({
                      url: '../filterCoreRecord/filterCoreRecord?eq_sn=' + that.data.facility_num,
                  })
              }else{
                  app.showToast('设备不存在');
                  return false;
              }
          }
      })

  },
})